package com.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class QuartzMain {
    public static void main(String[] args) throws SchedulerException, InterruptedException {
        //1.用Job接口的实现类build一个jobDetail对象
        JobDetail jobDetail = JobBuilder.newJob(HelloQuartz.class).build();

        //2.创建简单trigger(只跑一次),设置间隔1秒,并设置repeatforever
        SimpleTrigger simpleTrigger = TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).repeatForever()).build();

        //3.创建schedule对象
        Scheduler defaultScheduler = StdSchedulerFactory.getDefaultScheduler();

        defaultScheduler.scheduleJob(jobDetail, simpleTrigger);
        defaultScheduler.start();

        Thread.sleep(4000);

        defaultScheduler.shutdown();
    }
}
